package com.tbit.main.service.impl;

import com.tbit.main.dao.core.MachineLastUseDao;
import com.tbit.main.pojo.MachineLastUse;
import com.tbit.main.service.MachineLastUseService;
import com.tbit.main.util.StringUtil;
import org.apache.commons.collections4.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * 设备最后使用
 *
 * @author Leon
 * 2019年11月17日 下午2:40:35
 */
@Service("machineLastUseService")
public class MachineLastUseServiceImpl implements MachineLastUseService {
    @Autowired
    private MachineLastUseDao machineLastUseDao;

    @Override
    public MachineLastUse getByMachineId(Integer machineId) {
        return machineLastUseDao.getByMachineId(machineId);
    }

    @Override
    public void insert(MachineLastUse machineLastUse) {
        machineLastUseDao.insert(machineLastUse);
    }

    @Override
    public void update(MachineLastUse machineLastUse) {
        machineLastUseDao.update(machineLastUse);
    }

    @Override
    public List<MachineLastUse> getByMachineIds(List<Integer> machineIds) {

        List<MachineLastUse> machineLoses = new LinkedList<>();
        List<List<Integer>> machine = ListUtils.partition(machineIds, 900);
        for (List<Integer> m : machine) {
            machineLoses.addAll(machineLastUseDao.getByMachineIds(StringUtil.getListString(m)));
        }

        return machineLoses;
    }

}
